
#ifndef HOMEWINDOW_H
#define HOMEWINDOW_H

#include "core/basewindow.h"

#include <ConcurrentWorker.h>
#include <QLabel>
#include <sqliteutils.h>
#include <config/config.h>
#include <dialog/baudrate_dialog.h>
#include <service/serialportservice.h>
#include <widget/ecgwavewidget.h>

QT_BEGIN_NAMESPACE
namespace Ui { class HomeWindow; }
QT_END_NAMESPACE

class HomeWindow : public BaseWindow
{
    Q_OBJECT
public:
    //主页面
    explicit HomeWindow(QWidget *parent = nullptr);
    ~HomeWindow();
    void showEvent(QShowEvent *event) override;
    //波特率
    int baudRate = Config::BAUD_RATE_DEFAULT;
    //连接设备事件
    void onConnectButtonClicked();
    //连接状态
    bool isConnect  = false;
    void setupWorker();
protected:
    void initUI() override ;
    void initStyle() override ;

private slots:
    void on_action_triggered();
    void onDataProduced(const QList<int> &data);
    void onWorkerStarted();
    void onWorkerStopped();

private:
    Ui::HomeWindow *ui;
    void initStatusBar();
    QLabel *labViewCord;
    QLabel *labViewMessage;
    QLabel *labViewMeasure;
    QPushButton *btnLinkDevice = nullptr;
    void initMenuBar();
    bool is_initUi = false;
    BaudRateDialog *dlgBaudRate = nullptr;
    SerialPortService *serialPortService  = nullptr;
    void initSerialPortService();
    void initECGWidget();
    EcgWaveWidget *wave = nullptr;
    void setLabViewMeasureText(const QString &txt);
    void initGainAndSpeed();
    void initSimulateData();
    QTimer *timer = nullptr;
    ConcurrentWorker *m_worker = nullptr;
};

#endif // HOMEWINDOW_H
